//
//  NSUserDefaults+Tools.m
//  CityFire
//
//  Created by liuyangzhu on 2017/8/3.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "NSUserDefaults+Tools.h"

@implementation NSUserDefaults (Tools)

/**
 存储用户偏好设置到NSUserDefults

 @param data data
 @param key key
 */
+ (void)writeUserDataWithKey:(id)data forKey:(NSString*)key
{
    if (data == nil)
    {
        return;
    }
    
    else
    {
        [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

/**
 读取数据
 
 @param key key
 @return data
 */
+ (id)readUserDataWithKey:(NSString*)key
{
    id temp = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    
    if(temp != nil)
    {
        return temp;
    }
    
    return nil;
}
/**
 删除数据

 @param key key
 */
+ (void)removeUserDataWithkey:(NSString*)key
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
}

@end
